package com.blog.web.controller;

import com.blog.common.core.domain.R;
import com.blog.common.core.web.domain.AjaxResult;
import com.blog.common.core.web.page.TableDataInfo;
import com.blog.common.domain.vo.TalkVo;
import com.blog.web.service.TalkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 说说控制器
 * </p>
 *
 * @author Valerie
 * @date 2023/3/2
 **/
@Api(tags = "说说模块")
@RestController
public class TalkController {

    @Resource
    private TalkService talkService;

    /**
     * 查看首页说说
     *
     * @return {@link R<List<String>>}
     */
    @ApiOperation(value = "查看首页说说")
    @GetMapping("/home/talks")
    public R<List<String>> listHomeTalks() {
        return R.ok(talkService.listHomeTalks());
    }

    /**
     * 查看说说列表
     *
     * @return {@link R<TableDataInfo<TalkVo>>}
     */
    @ApiOperation(value = "查看说说列表")
    @GetMapping("/talks")
    public R<TableDataInfo<TalkVo>> listTalks() {
        return R.ok(talkService.listTalks());
    }

    /**
     * 根据id查看说说
     *
     * @param talkId 说说id
     * @return {@link R<TalkVo> }
     */
    @ApiOperation(value = "根据id查看说说")
    @ApiImplicitParam(name = "talkId", value = "说说id", required = true, dataType = "Integer")
    @GetMapping("/talks/{talkId}")
    public R<TalkVo> getTalkById(@PathVariable("talkId") Serializable talkId) {
        return R.ok(talkService.getTalkById(talkId));
    }

    /**
     * 点赞说说
     *
     * @param talkId 说说id
     * @return {@link R<Void>}
     */
    @ApiOperation(value = "点赞说说")
    @ApiImplicitParam(name = "talkId", value = "说说id", required = true, dataType = "Integer")
    @PostMapping("/talks/{talkId}/like")
    public R<Void> saveTalkLike(@PathVariable("talkId") Serializable talkId) {
        talkService.saveTalkLike(talkId);
        return R.ok();
    }









}
